﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Azure.Core
{
    internal enum ErrorHandlingOperation
    {
        STOPPARSE = 0,
        REDIRECT = 1,
        CONTINUE = 2
    }

    internal class AzErrorHandling
    {
        private ErrorHandlingOperation _operation = ErrorHandlingOperation.STOPPARSE;
        private String _param = String.Empty;

        public ErrorHandlingOperation Operation { get { return _operation; } }
        public String Param { get { return _param; } }

        public AzErrorHandling(String operation, String param)
        {
            _operation = (ErrorHandlingOperation)Enum.Parse(typeof(ErrorHandlingOperation), operation.ToUpper());
            _param = param;
        }

        public AzErrorHandling(ErrorHandlingOperation operation, String param)
        {
            _operation = operation;
            _param = param;
        }
    }

    internal class AzUriTarget
    {
        private String _name = String.Empty;
        private AzFormula _formula = null;
        private String _parserName = String.Empty;
        private List<AzErrorHandling> _errorHandlingList = null;

        private int _currentErrorHandlingIndex = 0;

        public String Name { get { return _name; } }
        public AzFormula Formula { get { return _formula; } }
        public String ParserName { get { return _parserName; } }

        public AzUriTarget(String name, String parserName, AzFormula formula)
        {
            _name = name;
            _formula = formula;
            _parserName = parserName;
            _errorHandlingList = new List<AzErrorHandling>();
        }

        public void AddErrorHandling(AzErrorHandling errorHandling)
        {
            _errorHandlingList.Add(errorHandling);
        }

        public AzErrorHandling GetCurrentErrorHandling()
        {
            AzErrorHandling result = null;

            if (_currentErrorHandlingIndex <_errorHandlingList.Count)
            {
                //返回当前_currentErrorHandlingIndex指向的那个，并将指针指向下一个
                result = _errorHandlingList[_currentErrorHandlingIndex++];
            }

            return result;
        }
    }
}
